package com.sm.honkon.app.utils;

import com.sm.honkon.app.App;
import com.sm.honkon.app.event.AppViewModel;
import com.sm.honkon.app.event.EventViewModel;
import com.sm.honkon.app.event.ReadDataEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by sm on 2019/1/14.
 */

public class CommondData {

    AppViewModel appViewModel;
    EventViewModel eventViewModel;

    public static byte[] START_CONTROL = {0x01, 0x11, 0x00, 0x00, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    public static byte[] STOP_CONTROL = {0x01, 0x11, 0x00, 0x11, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};

    public static byte[] START_TEST = {0x01, (byte) 0xE1, 0x00, (byte) 0xE1, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    public static byte[] STOP_TEST = {0x01, (byte) 0xE2, 0x00, (byte) 0xE2, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};

    public static byte[] LIGHT_MODE = {0x01, 0x33, 0x00, 0x00, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};

    public static byte[] YU_RAN_START = {0x01, 0x55, 0x00, 0x55, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    public static byte[] YU_RAN_STOP = {0x01, 0x55, 0x00, 0x00, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};

    public static byte[] RUN_START = {0x01, 0x66, 0x00, 0x66, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    public static byte[] RUN_STOP = {0x01, 0x66, 0x00, 0x00, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};

    public static byte[] CHECK = {0x01, 0x26, 0x00, 0x00, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};


    private static CommondData commondData;

    private CommondData() {
        appViewModel = App.instance.getAppViewModelProvider().get(AppViewModel.class);
        eventViewModel = App.instance.getAppViewModelProvider().get(EventViewModel.class);
    }

    public static CommondData getInstance() {
        if (commondData == null)
            commondData = new CommondData();
        return commondData;
    }

    public byte[] makeVolt(int i1, int i2) {
        return new byte[]{0x01, 0x22, (byte) ((i1 >> 8) & 0xff), (byte) (i1 & 0xff), (byte) ((i2 >> 8) & 0xff), (byte) (i2 & 0xff), (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }

    public byte[] makeMode(byte i) {
        return new byte[]{0x01, 0x33, 0x00, i, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }

    public byte[] makeFreqL(byte i) {
        return new byte[]{0x01, 0x44, 0x00, i, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }

    public byte[] makeWave(byte i) {
        return new byte[]{0x01, (byte) 0xDD, 0x00, i, 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }

    public byte[] makeTemplate(int high, int low) {
        return new byte[]{0x01, 0x27, (byte) ((high >> 8) & 0xff), (byte) (high & 0xff), (byte) ((low >> 8) & 0xff), (byte) (low & 0xff), (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }


    public byte[] makeTime(int i1, int i2) {
        return new byte[]{0x01, (byte) 0x88, (byte) ((i1 >> 8) & 0xff), (byte) (i1 & 0xff), (byte) ((i2 >> 8) & 0xff), (byte) (i2 & 0xff), (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }

    public byte[] makeHonemiao(int i1) {
        return new byte[]{0x01, (byte) 0x77, 0x00, (byte) (i1 & 0xff), 0x00, 0x00, (byte) 0xCC, 0x33, (byte) 0xC3, 0x3C};
    }


    public void readDataByte(int[] data) {
        EventBus.getDefault().post(new ReadDataEvent(data));
    }
}
